package org.teremail.mailbox;

import static java.lang.Integer.parseInt;

import java.util.Properties;

import com.google.inject.Inject;
import com.google.inject.Provider;

public class EhCacheMailboxDAOProvider implements Provider<EhCacheMailboxDAO> {

    private final Properties configuration;
    private final MailboxDAO mailboxDAO;

    @Inject
    public EhCacheMailboxDAOProvider(@Physical MailboxDAO mailboxDAO, Properties configuration) {
        this.mailboxDAO = mailboxDAO;
        this.configuration = configuration;
    }
    
    @Override
    public EhCacheMailboxDAO get() {
        int maxCacheElements = parseInt(configuration.getProperty("ehcache.mailbox.maxCacheElements"));
        int timeToLive = parseInt(configuration.getProperty("ehcache.mailbox.timeToLive"));
        return new EhCacheMailboxDAO(mailboxDAO, maxCacheElements, timeToLive);
    }
}
